package view;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTabbedPane;
import model.GlobalParams;

public class TabPannel  extends JTabbedPane {	
	
	private static final long serialVersionUID = 1L;

	public TabPannel (MainFrame frame , BrowsePanel bp) {
		
		this.frame  = frame;
		this.browse = bp;
		this.add("Tab " + counter , generateDiskContent());		
		this.addMouseListener(new Mouse(this));
	
		
	}
	
	public DiskContentPanel generateDiskContent() {
		counter++;
		return new DiskContentPanel(frame,browse,GlobalParams.getInstance().defaultLook);		
	}
	
	class Mouse implements MouseListener {	
		
		private TabPannel tab;		
		Mouse(TabPannel tp) {this.tab = tp;}
		
		@Override
		public void mouseClicked(MouseEvent arg0) {	
			
			if (arg0.getButton() == MouseEvent.BUTTON3) {
				if (getComponentCount() != 1) {
					tab.remove(getSelectedComponent());
					return;
				}				
			}			
			
			if (arg0.getClickCount() == 2) {				
				tab.add("Tab " + tab.counter, generateDiskContent());
				return;
			}			
		}

		@Override
		public void mouseEntered(MouseEvent arg0) {}
		@Override
		public void mouseExited(MouseEvent arg0)  {}
		@Override
		public void mousePressed(MouseEvent arg0) {}
		@Override
		public void mouseReleased(MouseEvent arg0){}		
	};
	
	
	public DiskContentPanel getPrimaryTab() {		
		return (DiskContentPanel)this.getSelectedComponent();
	}
	
	
	public void updateNames() {		
		for (int i=0; i < getComponentCount() ; i++){			
			((DiskContentPanel)getComponentAt(i)).updateNames();			
		}	
	}
	

	
	private MainFrame frame;
	private BrowsePanel browse;
	public int counter = 0;
	
	
	
}


